package cotizador.CotizadorWEB.notas;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping(value="/notas")
public class NotasController {
	
	
	@Autowired
	private NotasRepository notasRepository;

	@RequestMapping(value="/listar")
	public void listar(ModelMap modelMap) {
		List<Notas> notas = notasRepository.findAll();
	//	System.out.println("hay clientes " + clientes.size());
		modelMap.addAttribute("listaNotas", notas);
	}
	
	@RequestMapping(value="/crear")
	public NotasForm crear() {
		System.out.println("crear GET");
		return new NotasForm();
	}
	
	
	@RequestMapping(value="/eliminar", method = RequestMethod.POST)
	public String eliminar(@ModelAttribute Notas notas) {
		System.out.println("crear POST");
		notasRepository.delete(notas);
		return "redirect:/notas/listar";
	}

	@RequestMapping(value="/crear", method = RequestMethod.POST)
	public String crear(@ModelAttribute NotasForm notasForm) {
		System.out.println("crear POST");
		notasRepository.save(notasForm.createNotas());
		return "redirect:/notas/listar";
	}

}
